package com.sharing.controller;

import com.sharing.common.Page;
import com.sharing.common.Result;
import com.sharing.domain.Hobby;
import com.sharing.domain.UserHobby;
import com.sharing.domain.dto.UserDto;
import com.sharing.service.UserHobbyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @author MingTian
 * @version 1.0
 * @description TODO
 * @date 2023/4/3 10:29
 */
@RestController
@RequestMapping("/userHobby")
public class UserHobbyController {
    @Autowired
    private UserHobbyService userHobbyService;

    /**
     * 根据用户Id查询用户的兴趣
     * @param userId
     * @return
     */
    @GetMapping("/userId")
    public Result<Page<Hobby>> selectHobbyByUserId(Integer userId, Integer level, Integer page, Integer size) {
        return userHobbyService.selectHobbyByUserId(userId, level, page, size);
    }

    /**
     * 根据兴趣查询用户基本信息
     * @param hobbies
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/users")
    public Result<Page<UserDto>> selectUsersByHobby(@RequestParam List<String> hobbies, Integer page, Integer size) {
        return userHobbyService.selectUsersByHobby(hobbies, page, size);
    }


    /**
     * 新增用户兴趣————单个
     * @param userHobby
     * @return
     */
    @PostMapping
    public Result<UserHobby> insertHobby(@RequestBody UserHobby userHobby) {
        return userHobbyService.insertHobby(userHobby);
    }

    /**
     * 新增用户兴趣————多个
     * @param userHobbies
     * @return
     */
    @PostMapping("/mult")
    public Result<Integer> insertHobbies(@RequestBody List<UserHobby> userHobbies) {
        return userHobbyService.insertHobbies(userHobbies);
    }

    /**
     * 删除用户兴趣————多个
     * @param hobbyIds
     * @param userId
     * @return
     */
    @DeleteMapping("/mult")
    public Result<Integer> deleteHobbies(@RequestParam List<Integer> hobbyIds, Integer userId) {
        return userHobbyService.deleteHobbies(hobbyIds, userId);
    }
}
